Skip to content

Avoid copying uninitialized float64 buffers to the device in tests - #3110

Merged
antonwolfy merged 2 commits into
masterfrom
fix-uninit-out-arrays-in-tests
Oct 20, 2026
Merged

antonwolfy merged 2 commits into
masterfrom
fix-uninit-out-arrays-in-tests

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Four tests built an output array with numpy.empty in float64 and copied it to the device with dpnp.array:

  • TestDot::test_out_scalar in test_product.py (numpy.result_type(int, float32_array) is float64)
  • TestMatmul::test_syrk_out_order in test_product.py (generate_random_numpy_array defaults to float64)
  • TestVecdot::test_out_0D in test_product.py
  • TestNanProdSum::test_out in test_nanfunctions.py

On a device without fp64 support the copy casts the buffer to float32. If the uninitialized memory happens to hold a value beyond the float32 range, NumPy raises RuntimeWarning: overflow encountered in cast, so the warning appears at random in test runs on such devices (it was seen for TestDot::test_out_scalar[float32] on a Windows GPU).

The buffers are now created with numpy.zeros. In TestNanProdSum::test_out, where only a wrongly shaped out array is needed, it is allocated on the device with dpnp.empty instead. Only test files are changed.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

Four tests built an output array with `numpy.empty` in float64 and copied
it to the device with `dpnp.array`. On a device without fp64 support the
copy casts to float32, and if the uninitialized memory holds a value
beyond the float32 range, NumPy raises `RuntimeWarning: overflow
encountered in cast`. Initialize the buffers with `numpy.zeros`, or
allocate on the device with `dpnp.empty` where the numpy array isn't
needed.
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Oct 15, 2026
@antonwolfy antonwolfy self-assigned this Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3110/index.html

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev15=np2py314h8d9cdd5_8 ran successfully.
Passed: 1376
Failed: 0
Skipped: 6

@coveralls

coveralls commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 82.613% — fix-uninit-out-arrays-in-tests into master. No base build found for master.

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you @antonwolfy

@antonwolfy
antonwolfy merged commit 876330b into master Oct 20, 2026
107 of 112 checks passed
@antonwolfy
antonwolfy deleted the fix-uninit-out-arrays-in-tests branch October 20, 2026 17:01
github-actions Bot added a commit that referenced this pull request Oct 20, 2026
…3110)

Four tests built an output array with `numpy.empty` in float64 and
copied it to the device with `dpnp.array`:

- `TestDot::test_out_scalar` in `test_product.py`
(`numpy.result_type(int, float32_array)` is float64)
- `TestMatmul::test_syrk_out_order` in `test_product.py`
(`generate_random_numpy_array` defaults to float64)
- `TestVecdot::test_out_0D` in `test_product.py`
- `TestNanProdSum::test_out` in `test_nanfunctions.py`

On a device without fp64 support the copy casts the buffer to float32.
If the uninitialized memory happens to hold a value beyond the float32
range, NumPy raises `RuntimeWarning: overflow encountered in cast`, so
the warning appears at random in test runs on such devices (it was seen
for `TestDot::test_out_scalar[float32]` on a Windows GPU).

The buffers are now created with `numpy.zeros`. In
`TestNanProdSum::test_out`, where only a wrongly shaped `out` array is
needed, it is allocated on the device with `dpnp.empty` instead. Only
test files are changed. 876330b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants